<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2017/12/1
 * Time: 11:37
 */

namespace App\Http\Controllers\VipChannel\User;

use App\Http\Controllers\Controller;
use App\Modules\Channel\Services\ChannelUserService;
use App\Modules\User\Services\VipManageService;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function login(Request $request){
        \Log::info('into login');
        $username = $request->input('username','');
        $password = $request->input('pwd','');
        if(empty($username) || empty($password)) {
            return response()->error('PARAM_EMPTY');
        }
        $password = md5($password.'^-^zhuishuyun^_^');
        #VIP用户
        $manage_info = VipManageService::judgeLogin($username,$password);
        if(!($manage_info->isEmpty())) {
            \Log::info('$manage_info not empty');
            $request->session()->put('user_type','manage');
            $request->session()->put('uid',$manage_info[0]->id);
            $request->session()->put('user_info',serialize($manage_info));
            return response()->success();
        }else{
            \Log::info('$manage_info is empty');
        }
        #分销用户
        $channel_users_info = ChannelUserService::judgeLogin($username,$password);
        if($channel_users_info) {
            \Log::info('$manage_info not empty');
            $request->session()->put('user_type','channel_user');
            $request->session()->put('uid',$channel_users_info->id);
            $request->session()->put('user_info',serialize($channel_users_info));
            return response()->success();
        }
        return response()->error('LOGIN_VERIFY_ERROR');
    }
}